package controller

import (
	"gin_server/internal/request"
	"gin_server/internal/service"
	"gin_server/pkg/response"

	"github.com/gin-gonic/gin"
)

type AppUserController struct {
	service service.UserService
}

func NewAppUserController(s service.UserService) *AppUserController {
	return &AppUserController{service: s}
}

// Register 用户注册
// @Summary 用户注册
// @Description 用户注册接口，支持使用account或self_account进行注册
// @Tags 用户
// @Accept json
// @Produce json
// @Param entity body request.RegisterRequest true "注册信息"
// @Success 200 {object} response.Response{data=model.User}
// @Router /app/user/reg [post]
func (c *AppUserController) Register(ctx *gin.Context) {
	var req request.RegisterRequest
	if err := ctx.ShouldBindJSON(&req); err != nil {
		response.BadRequest(ctx, err.Error())
		return
	}

	// 调用服务层进行注册
	user, err := c.service.Register(&req)
	if err != nil {
		response.Error(ctx, "注册失败")
		return
	}

	response.SuccessWithMessage(ctx, "注册成功", user)
}
